package com.ld.control.business.equipment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ld.control.business.equipment.mapper.EquipmentMethodDebugParamMapper;
import com.ld.control.business.equipment.model.EquipmentMethodDebugParamModel;
import com.ld.control.business.equipment.service.EquipmentMethodDebugParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * <p>
 * 设备方法参数表 服务实现类
 * </p>
 *
 * @author wangfeng
 * @since 2024-04-19
 */
@Service
public class EquipmentMethodDebugParamServiceImpl extends ServiceImpl<EquipmentMethodDebugParamMapper, EquipmentMethodDebugParamModel> implements EquipmentMethodDebugParamService {

    @Autowired
    private EquipmentMethodDebugParamMapper equipmentMethodDebugParamMapper;
    
    @Override
    public Map<String, EquipmentMethodDebugParamModel> getMap(Long equipmentMethodTmpId) {
        Map<String, EquipmentMethodDebugParamModel> equipmentMethodDebugParamModelMap = new HashMap<>();
        QueryWrapper<EquipmentMethodDebugParamModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(EquipmentMethodDebugParamModel.EQUIPMENT_METHOD_TMP_ID, equipmentMethodTmpId);
        List<EquipmentMethodDebugParamModel> equipmentMethodDebugParamModelList = equipmentMethodDebugParamMapper.selectList(queryWrapper);
        if (!CollectionUtils.isEmpty(equipmentMethodDebugParamModelList)) {
            equipmentMethodDebugParamModelMap = equipmentMethodDebugParamModelList.stream().collect(Collectors
                    .toMap(EquipmentMethodDebugParamModel::getName, Function.identity()));
        }
        return equipmentMethodDebugParamModelMap;
    }
}
